<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('融资时间')" prop="financingTime">
            <el-date-picker
              v-model="form.financingTime"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('融资时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('披露时间')" prop="disclosureTime">
            <el-date-picker
              v-model="form.disclosureTime"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('披露时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('投资方')" prop="investor">
            <el-input v-model="form.investor" :placeholder="$t('投资方')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('交易金额')" prop="transactionAmount">
            <el-input v-model="form.transactionAmount" :placeholder="$t('交易金额')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('投资比例(%)')" prop="investmentRatio">
            <Ratio v-model="form.investmentRatio" :placeholder="$t('投资比例')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('融资轮次')" prop="rounds">
            <el-input v-model="form.rounds" :placeholder="$t('融资轮次')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('估值')" prop="valuation">
            <el-input v-model="form.valuation" :placeholder="$t('估值')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('新闻标题')" prop="newsTitle">
            <el-input v-model="form.newsTitle" :placeholder="$t('新闻标题')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('新闻链接')" prop="newsUrl">
            <el-input v-model="form.newsUrl" :placeholder="$t('新闻URL')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="company:financeTyc" :save-show="sourceType !== 'bussRisk'" />
    </div>
  </div>
</template>

<script>
    import { saveCompanyFinanceTyc, getCompanyFinanceTyc } from '@/api/company/finance/companyFinanceTyc'
    export default {
        props: {
          sourceType: {
            type: String,
            default: ''
          }
        },
        data() {
            return {
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                  financingTime: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                  disclosureTime: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  investor: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  transactionAmount: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  investmentRatio: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  rounds: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ],
                  valuation: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                  ]
                }
            }
        },
        created() {
        },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                    getCompanyFinanceTyc(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    companyId: this.$route.query.companyId,
                    financingTime: undefined,
                    disclosureTime: undefined,
                    investor: undefined,
                    transactionAmount: undefined,
                    investmentRatio: undefined,
                    rounds: undefined,
                    valuation: undefined,
                    newsTitle: undefined,
                    newsUrl: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            // 提交按钮
            submitForm() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveCompanyFinanceTyc(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                              if (this.$route.query.companyId) {
                                this.$store.dispatch('bussRisk/UPDATE_BUSS_RISK_COUNT', { id: this.$route.query.companyId })
                              }
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                })
           }

        }

    }
</script>
